/*	Key_Generator.h
 *	Copyright (C) 2008 CRIMERE
 *	Copyright (C) 2008 Jean-Marc Mercier
 *	
 *	This file is part of OTS (optimally transported schemes), an open-source library
 *	dedicated to scientific computing. http://code.google.com/p/optimally-transported-schemes/
 *
 *	CRIMERE makes no representations about the suitability of this
 *	software for any purpose. It is provided "as is" without express or
 *	implied warranty.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*
	A small structure that allow to create unique indexes for objects.
*/
#if !defined(_Key_Generator_)
#define _Key_Generator_

	template <class key_type = long>
	class Key_generator 
	{
	public :
		typedef Key_generator	key_generator_type;
		typedef key_type		key_type;
		Key_generator(){
			key_ = key_singleton::instance()();
		};
		key_type get_key()const{return key_;} ;
	private :
		struct key_singleton_type 
		{
			key_singleton_type () : key_(0) {};
			key_type operator()() {return ++key_;};
			key_type key_;
		};
		typedef Singleton<key_singleton_type > key_singleton;
		key_type key_;
	};

#endif

